package com.enterprise.struts2.news;

import org.apache.struts2.components.If;

import com.enterprise.daoImpl.NodeDaoImpl;
import com.enterprise.domain.Node;
import com.opensymphony.xwork2.ActionSupport;

public class NodeAction extends ActionSupport{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private int id;
	private String className;
	private int parentId;
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getClassName() {
		return className;
	}
	public void setClassName(String className) {
		this.className = className;
	}
	public int getParentId() {
		return parentId;
	}
	public void setParentId(int parentId) {
		this.parentId = parentId;
	}
	
	public String insert(){
		if(parentId<=0)
			parentId=-1;
		Node node=new Node(1,className,parentId);
		if(new NodeDaoImpl().insertNode(node)>0)
			return "success";
		else {
			this.addActionError("insert wrong!");
			return "input";
		}
	}
	
	public String update(){
		Node node=new Node(id,className,parentId);
		System.out.println(node);
		if(new NodeDaoImpl().updateNode(node)>0){
			System.out.println(node);
			return "success";
		}
		else {
			this.addActionError("insert wrong!");
			return "input";
		}
	}
	
	public String delete(){
		Node node=new Node(id,className,parentId);
		if(new NodeDaoImpl().deleteNode(node)>0)
			return "success";
		else {
			this.addActionError("insert wrong!");
			return "input";
		}
	}

}
